<template>
	<view>
		<view class="order-content">
			<view>{{assessInfo['考核项目']}}</view>
			<view style="margin-bottom: 40rpx;">

				<view class="detail-title">
					<text>考核记录</text>
				</view>
				<view class="content-item">
					<text class="item-name">所属社区：</text>
					<view class="right-content">{{ assessInfo['所属社区']}}</view>
				</view>
				<view class="content-item">
					<text class="item-name">小区名称：</text>
					<view class="right-content">{{ assessInfo['小区名称']}}</view>
				</view>
				<view class="content-item">
					<text class="item-name">物业单位：</text>
					<view class="right-content">{{ assessInfo['物业单位']}}</view>
				</view>
				<!-- <view class="content-item">
					<text class="item-name">检查部门：</text>
					<view class="right-content">{{ 'XX部门、XXA部门'}}</view>
				</view> -->
				<view class="content-item">
					<text class="item-name">执行人员：</text>
					<view class="right-content">{{ assessInfo['物业负责人']}}</view>
				</view>
				<view class="content-item">
					<text class="item-name">检查次数：</text>
					<view class="right-content">{{ assessInfo['检查次数']}}</view>
				</view>
				<view class="content-item">
					<text class="item-name">综合分数：</text>
					<view class="right-content">{{ assessInfo['综合得分']}}</view>
				</view>
			</view>
			<view style="margin-bottom: 40rpx;">
				<view class="detail-title">
					<text>考核详情</text>
				</view>
			</view>
		</view>
		<!-- <view style="margin-top: -140rpx;">
			<assess-table @submit="onSubmit" ref="assessTable" :list="assessInfo['考核事项']"></assess-table>
		</view> -->
		
		<view v-for="item in assessInfo['考核事项']" :key="item.id">
			<view  class="check-title">{{item['事项名称']}}</view>
		
			<view v-if="item['考核细则']">
				<view  class="check-item" :key="subItem.id" v-for="(subItem,index) in item['考核细则']">
					<view>
						{{index+1}}、{{subItem['考核要求']}}（扣分上限{{subItem['分数上限']}}分）
					</view>
					<view class="assess-result">
						<view class="assess-result-item">平均得分: {{subItem['平均得分'].toFixed(2)}}</view>
						<view class="assess-result-item assess-flex">
							<text>考核记录</text>
							<text @click="showRecord(item, subItem)" style="color: #1152FC;">{{subItem.show ? '隐藏':'查看'}}</text>
						</view>
						<wyb-table v-if="subItem.contents"  @onCheck="handleCheck" enable-check="single"  ref="table" :url-col="urlCol" width="660rpx"  first-line-fixed :default-col-width="160"  :headers="headers" :contents="subItem.contents" :sort-ways="sortWays" />
					</view>
				</view>
				
			</view>
			
			<view v-if="item['子事项']">
				<view  class="check-item" v-for="(subItem,index) in item['子事项']" :key="subItem.id">
					<view  class="check-child-title">{{subItem['事项名称']}}</view>
					
					<view v-for="childItem in subItem['考核细则']" :key="childItem.id">
						<view>
							{{index+1}}、{{childItem['考核要求']}}（上限{{childItem['分数上限']}}分）
						</view>
						<view class="assess-result">
							<view class="assess-result-item">平均得分: {{childItem['平均得分'].toFixed(2)}}</view>
							<view class="assess-result-item assess-flex">
								<text>考核记录</text>
								<text @click="showRecord(subItem, childItem)" style="color: #1152FC;">{{childItem.show ? '隐藏':'查看'}}</text>
							</view>
							<wyb-table v-if="subItem.contents" @onCheck="handleCheck" enable-check="single" ref="table" :url-col="urlCol" width="660rpx"  first-line-fixed :default-col-width="160"  :headers="headers" :contents="childItem.contents" :sort-ways="sortWays" />
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<van-dialog
		  use-slot
		  title="考核记录"
		  :show="show"
		  confirm-button-color="#1152FC"
		  confirm-button-open-type="getUserInfo"
		  @close="onClose"
		>
			<view class="dialog-padding">
				<view @click="handleAppeal" class="appeal-box">
					<view class="appeal-icon">
						<image src="../../static/shensu.png"></image>
					</view>
					申诉
				</view>
				<view style="display: flex;justify-content: center;">
					<wyb-table   @onCheck="handleCheck" enable-check="single"  ref="table" :url-col="urlCol" width="570rpx"  first-line-fixed :default-col-width="160"  :headers="headers" :contents="contents" :sort-ways="sortWays" />
				</view>
				
			</view>
		  
		</van-dialog>
		
		<!-- <button v-if="appealRecord.length" @click="handleAppeal" class="assess-submit-btn">申诉</button> -->
	</view>

</template>

<script>
	import wybTable from '@/components/wyb-table/wyb-table.vue'
	import assessTable from '../components/assessTable.vue'
	export default {
		components: {
			wybTable,
			assessTable
		},
		data() {
			return {
				show: false,
				appealRecord: [],
				headers: [{
				    label: '序号',
				    key: 'index',
					width: 80
				}, {
				    label: '分值',
				    key: '得分',
					width: 80
				},{
				    label: '问题描述',
				    key: '问题描述',
					width: 220
				}, {
				    label: '记录图片',
				    key: 'url',
					width: 120
				}],
				urlCol: [{
				    type: 'route',
				    key: 'url'
				}],
				sortWays: ['inv', 'none', 'asc'],
				contents: [],
				isShow: false,
				assessInfo: {},
				assessRecord: [],
				params: {
					
				},
				params1: {}
			}
		},
		onLoad(options) {
			this.params = {...JSON.parse(options.item), 项目id: +options.projId}
			// this.params = JSON.parse(options.item)
			this.params1 = {...JSON.parse(options.item), 内容id: null, 项目id: +options.projId}
			this.initDetail()
		},
		methods: {
			onClose() {
				this.show = false
				this.appealRecord = []
			},
			handleCheck(e) {
				this.appealRecord = e.data
				// console.log(e.data[0].lineData)
			},
			async initDetail() {
				this.assessRecord = await this.getAssessRecord()
				this.assessInfo = await this.getAssessDetail()
			},
			showRecord(obj, childObj) {
				this.contents = this.assessRecord.filter(item => obj.id == item.事项id && childObj.id == item.内容id)
				this.contents.forEach((item,index) => {
					item.index = index + 1
					item.url = ['查看','/assessSystem/assessRecordDetail/assessRecordDetail?item=' + JSON.stringify(item) + '&info=' + JSON.stringify(childObj)]
				})
				this.show = true
			},
			getAssessDetail() {
				uni.showLoading()
				return new Promise((resolve,reject) => {
					this.$http2.post('transactionCompete/detailEvaluateResult', this.params).then(res => {
						if(res.code === 10000) {
							// console.log('请求成功了吗')
							res.data.考核事项.forEach(item => {
								item.考核细则 = item.考核细则 || []
								item.子事项 = item.子事项 || []
							})
							for(let i = 0; i < res.data.考核事项.length; i++) {
								for(let j = 0; j < res.data.考核事项[i].考核细则.length; j++) {
									res.data.考核事项[i].考核细则[j].show = false
									// res.data.考核事项[i].考核细则[j].contents = this.assessRecord.filter(item => res.data.考核事项[i].id == item.事项id && res.data.考核事项[i].考核细则[j].id == item.内容id)
									// res.data.考核事项[i].考核细则[j].contents.forEach((item,index) => {
									// 	item.index = index + 1
									// 	item.url = ['查看','/assessSystem/assessRecordDetail/assessRecordDetail?item=' + JSON.stringify(item) + '&info=' + JSON.stringify(res.data.考核事项[i].考核细则[j])]
									// })
								}	
							 }
							 let childCheck = res.data.考核事项.map(item => item.子事项).reduce((a,b) => { return a.concat(b)})
							 for(let i = 0; i < childCheck.length; i++) {
							 	for(let j = 0; j < childCheck[i].考核细则.length; j++) {
							 		childCheck[i].考核细则[j].show = false
							 	// 	childCheck[i].考核细则[j].contents = this.assessRecord.filter(item => childCheck[i].id == item.事项id && childCheck[i].考核细则[j].id == item.内容id)
									// childCheck[i].考核细则[j].contents.forEach((item,index) => {
									// 	item.index = index + 1
									// 	item.url = ['查看','/assessSystem/assessRecordDetail/assessRecordDetail?item=' + JSON.stringify(item)]
									// })
								}	
							  }
						}
						resolve(res.data)
					})
				})
				
			},
			getAssessRecord() {
				return new Promise((resolve, reject) => {
					this.$http2.post('transactionCompete/listAssessmentItemRecord', this.params1).then(res => {
						if(res.code === 10000) {
							resolve(res.data.list)
						}
						
					})
				})
				
			},
			handleAppeal() {
				if(!this.appealRecord.length) {
					uni.showToast({
						title: '请选择申诉的记录',
						icon: 'none'
					})
					return
				}
				let record = JSON.parse(JSON.stringify(this.appealRecord[0].lineData))
				record.url = []
				record.附件 = []
				record.机构id = record.集团id
				// console.log(this.appealRecord[0].lineData)
				uni.navigateTo({
					url: '/assessSystem/recordAppeal/recordAppeal?record=' + JSON.stringify(record)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '../../style/info.scss';
	.appeal-icon {
		width: 32rpx;
		height: 32rpx;
		margin-right: 10rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.appeal-box {
		font-size: 28rpx;
		margin-bottom: 20rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		padding-right: 50rpx;
	}
	.dialog-padding {
		padding: 20rpx 0 40rpx;
	}
	.order-content {
		margin-bottom: 0!important;
	}
	.check-title {
			height: 80rpx;
			font-size: 40rpx;
			text-align: center;
			line-height: 60rpx;
			border-bottom: 2rpx solid #DEDEDE;
			margin-bottom: 30rpx;
		}
	.check-child-title {
			height: 60rpx;
			font-size: 32rpx;
			text-align: center;
			line-height: 40rpx;
			border-bottom: 2rpx solid #DEDEDE;
			margin-bottom: 30rpx;
		}
		.check-item {
			margin-bottom: 40rpx;
			font-size: 32rpx;
			padding: 0 20rpx;
			.unquality-check-item {
				width: 674rpx;
				height: 258rpx;
				padding: 20rpx;
				border: 2rpx solid #B5B5B5;
				margin-bottom: 20rpx;
	
				.desc {
					margin-bottom: 20rpx;
					display: flex;
	
					input {
						width: 450rpx;
					}
				}
	
				.img-content {
					display: flex;
	
					.img-item {
						width: 140rpx;
						height: 140rpx;
						margin: 10rpx;
	
						.img {
							width: 100%;
							height: 100%;
						}
					}
				}
			}
			.assess-result {
				margin-top: 20rpx;
				width: 700rpx;
				min-height: 160rpx;
				padding: 20rpx;
				border: 2rpx solid #B5B5B5;
				margin-bottom: 20rpx;
				.assess-result-item {
					margin-bottom: 20rpx;
				}
				.assess-flex {
					display: flex;
					justify-content: space-between;
				}
			}
		}
	
	.assess-title {
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
	}
	.assess-submit-btn {
		position: fixed;
		z-index: 99;
		height: 98rpx;
		text-align: center;
		color: #fff;
		line-height: 98rpx;
		left: 0;
		right: 0;
		bottom: 0;
		border-radius: 0;
		background-color: #1152FC;

		&::after {
			border-radius: 0;
		}
	}
</style>
